package com.ruoyi.dl.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dl.domain.DlProgress;
import com.ruoyi.dl.service.IDlProgressService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 进度上传Controller
 * 
 * @author ruoyi
 * @date 2020-12-28
 */
@Controller
@RequestMapping("/dl/progress")
public class DlProgressController extends BaseController
{
    private String prefix = "dl/progress";

    @Autowired
    private IDlProgressService dlProgressService;

    @RequiresPermissions("dl:progress:view")
    @GetMapping()
    public String progress()
    {
        return prefix + "/progress";
    }

    /**
     * 查询进度上传列表
     */
    @RequiresPermissions("dl:progress:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DlProgress dlProgress)
    {
        startPage();
        List<DlProgress> list = dlProgressService.newSelectDlProgressList(dlProgress);
        return getDataTable(list);
    }

    /**
     * 导出进度上传列表
     */
    @RequiresPermissions("dl:progress:export")
    @Log(title = "进度上传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DlProgress dlProgress)
    {
        List<DlProgress> list = dlProgressService.selectDlProgressList(dlProgress);
        ExcelUtil<DlProgress> util = new ExcelUtil<DlProgress>(DlProgress.class);
        return util.exportExcel(list, "progress");
    }

    /**
     * 新增进度上传
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存进度上传
     */
    @RequiresPermissions("dl:progress:add")
    @Log(title = "进度上传", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DlProgress dlProgress)
    {
        return toAjax(dlProgressService.insertDlProgress(dlProgress));
    }

    /**
     * 修改进度上传
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DlProgress dlProgress = dlProgressService.selectDlProgressById(id);
        mmap.put("dlProgress", dlProgress);
        return prefix + "/edit";
    }

    /**
     * 修改保存进度上传
     */
    @RequiresPermissions("dl:progress:edit")
    @Log(title = "进度上传", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DlProgress dlProgress)
    {
        return toAjax(dlProgressService.updateDlProgress(dlProgress));
    }

    /**
     * 删除进度上传
     */
    @RequiresPermissions("dl:progress:remove")
    @Log(title = "进度上传", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dlProgressService.deleteDlProgressByIds(ids));
    }
}
